<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const p = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('用户数据')
            }, 1000)
        })

        // then的返回结果也是Promise对象，对象状态由回调函数的执行结果决定
        // 1. 如果回调函数返回的是非promise类型，状态为成功，返回值则为对象成功的值
        // 2. 
        const result = p.then(res => {
            console.log(res)
            // 1. 非promise类型
            //return 123;
            // 2. 是promise类型
            /* return new Promise((resolve, reject) => {
                resolve('ok')
            }) */
            // 3. 抛出错误
            throw new Error('出错！');
        }, err => {
            console.error(err)
        })
        // 链式调用
        .then(value => {

        }, reason => {
            
        })
        console.log('result: ', result)



    </script>
</body>
</html>